﻿function MyUpload(uploadObjDom, save_id) {
	var url = window.location.origin;
	var fileObjDom = $(uploadObjDom);
	var filePath = fileObjDom.val();
	if (!filePath) {
		layer.msg('Select A File');
		return null;
	}
	var fileType = filePath.substr(filePath.lastIndexOf(".") + 1);
	var formData = new FormData();
	formData.append('file', fileObjDom[0].files[0]);
	formData.append('fileType', fileType);
	$.ajax({
		type : 'post',
		cache : false,
		url : url + '/file/upload',
		data : formData,
		dataType : 'json',
		processData : false,
		contentType : false,
		beforeSend : function() {
			layer.load();
		},
		success : function(res) {
			layer.closeAll();
			if (res.status == 0) {
				layer.msg("Upload Success");
				$(uploadObjDom).parents(".quickgo-file-main").children("img").attr("src", res.data).css("display", 'block');
				$("#" + save_id).val(res.data);
				$(uploadObjDom).parents("button").children("span").text("Upload Success");
			} else {
				layer.msg("Upload Fail");
				$(uploadObjDom).parents("button").children("span").text("Upload Fail");
			}
		},
		error : function(res, ajaxOptions, thrownError) {
			layer.closeAll();
			layer.msg('Request Error');
		}
	});
}